package cn.xinfei.xdecision.engine.runner.executor.strategy;

import cn.xinfei.xdecision.common.model.component.strategyout.StrategyOutput;
import cn.xinfei.xdecision.common.vo.FieldInfoVo;
import cn.xinfei.xdecision.engine.runner.executor.AbsNodeHandler;
import cn.xinfei.xdecision.engine.runner.executor.NodeHandler;
import cn.xinfei.xdecision.engine.runner.executor.model.StateTransmitModel;

import java.util.Map;
import java.util.Set;

/**
 * 引擎节点执行
 */

public interface IEngineRunner<T extends AbsNodeHandler> {

    public String getServiceName();


    void before(T nodeHandler);

    public void after(T nodeHandler, StateTransmitModel stateTransmitModel, Map<String, Object> nodeOutput, Map<String, Object> nodeInput);

    public void clear();

    /**
     * 获取引擎节点关联的变量
     *
     * @param nodeHandler
     */
    Map<String, FieldInfoVo> getInputFieldInfo(T nodeHandler);

    Map<String, FieldInfoVo> getTerminalInputFieldInfo(NodeHandler nodeHandler);


    Map<String, StrategyOutput> getOutputFieldInfo(T nodeHandler);

    /**
     * 节点终止条件输出
     *
     * @param nodeHandler
     * @return
     */
    Map<String, StrategyOutput> getTerminalOutputFieldInfo(T nodeHandler);

    /**
     * 获取节点所需的指标
     *
     * @param nodeHandler
     */
    void getNodeFieldValue(T nodeHandler) throws Exception;

    void getNodeFieldValue(Set<String> fieldSet, String nodeCode) throws Exception;


    /**
     * 执行节点逻辑
     *
     * @param nodeHandler
     */
    StateTransmitModel runNode(T nodeHandler) throws Exception;


    /**
     * 终止条件判断
     *
     * @param nodeHandler
     */
    boolean terminalCondition(T nodeHandler, Map<String, Object> nodeOutput, Map<String, Object> nodeInput);


    public Map<String, Object> getNodeOutput(T nodeHandler);

    public Map<String, Object> setNodeOutput(T nodeHandler);

    public Map<String, Object> getNodeInput(T nodeHandler);

    public void setOutput(T nodeHandler, String key, Object result);


}
